package test;

import common.Utils;
import org.openqa.selenium.By;

public class RegisterPage extends Utils {
    public static String url = "http://127.0.0.1:9580/sign-up.html";

    public RegisterPage() {
        super(url);
    }

    //正常注册
    public void register() throws InterruptedException {
        //测试是否正常打开
        driver.findElement(By.cssSelector("#signUpForm > div > h2"));
        //注册
        driver.findElement(By.cssSelector("#username")).sendKeys("25号");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("hz");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("123456");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();

        //检查是否注册成功
       String title =  driver.getTitle();
        assert title.equals("比特论坛 - 用户登录");
    }

    //异常注册
    public  void abnormalPassword() throws InterruptedException {
        driver.findElement(By.cssSelector("body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a")).click();
        //两次密码不一样
        driver.findElement(By.cssSelector("#username")).sendKeys("洪3");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("hz");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("12345");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();
    }

    public void abnormalUser(){
        //用户以存在
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#nickname")).clear();
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#passwordRepeat")).clear();
        driver.findElement(By.cssSelector("#username")).sendKeys("洪1");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("hz");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("123456");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();

        //点击已有账号登录
        driver.findElement(By.cssSelector("body > div > div > div.text-center.text-muted.mt-3 > a")).click();
    }
}
